﻿import RealisticBooks.BookSection;
import RealisticBooks.BookImage;
import RealisticBooks.BookLink;
import RealisticBooks.TextUtil;
/**
 * BookLine class
 * This code defined a BookLine class that holds the
 * information of a line in a book
 */

class RealisticBooks.BookLine {
	/**
	 * The x origin of the line
	 * @type Number
	 */
	public var  lineX:Number;
	/**
	 * The y origin of the line
	 * @type Number
	 */
	public var  lineY:Number;
	/**
	 * The width of the line
	 * @type Number
	 */
	public var  lineWidth:Number;
	/**
	 * The height of the line
	 * @type Number
	 */
	public var  lineHeight:Number;
	
	/**
	 * The size of the font in the line
	 * @type Number
	 */
	public var  fontSize:Number;
	/**
	 * The font family of the line
	 * @type String
	 */
	public var  fontFace:String;
	/**
	 * The font color of the line
	 * @type String
	 */
	public var fontColor:String;
	/**
	 * The paragraph alignment of the line
	 * @type String
	 */
	public var  lineAlign:String;
	/**
	 * This is the leading text value 
	 * (0 = no space, -ve = space at bottom, +ve = space at top)
	 * @type Number
	 */
	public var  lineLeading:Number = 0;
	
	/** 
	 * The last character index of this line
	 * @type Number
	 */
	public var  lineIndex:Number;
	/**
	 * This is the html text of the line
	 * @type String
	 */
	public var  lineText:String;
	/**
	 * This is the plain text version of the line
	 * @type String
	 */
	public var  plain_text:String;
	/**
	 * This is the collection of the starting tag of the line
	 * @type String
	 */
	public var  lineStartStyle:String;
	/**
	 * This is the collection of the ending tag of the line
	 * @type String
	 */
	public var  lineEndStyle:String;
	
	/**
	 * List of the hyperlinks information in this line
	 * @type Array
	 */
	public var  lineLinks:Array;
	/**
	 * An image stored in this line
	 * @type BookImage
	 */
	public var  lineImage:BookImage;
	/**
	 * List of the slide filename for the page
	 * @type Array
	 */
	public var lineSlidesname:Array;
	/**
	 * This line is part of the section title paragraph
	 * @type BookSection
	 */
	public var lineSection:BookSection;
	
	/**
	 * Whether this line is an indicator of a page break
	 */
	public var lineNewpage:Boolean;
	/**
	 * Whether the line was created from text splitting
	 * @type Boolean
	 */
	public var isLineBreak:Boolean;
	/**
	 * Whether this line is created as part of the back
	 * of the book index entry
	 * @type Number
	 */
	public var bobNumber:Number;
	
	public function BookLine () {
		this.lineX = 0;
		this.lineY = 0;
		this.lineWidth = 0;
		this.lineHeight = 0;
		
		this.fontSize = 12;
		this.fontFace = "arial";
		this.fontColor = "#000000";
		this.lineAlign = "left";
		this.lineLeading = 0;
		
		this.lineIndex = 0;
		this.lineText = "";
		this.plain_text = "";
		this.lineStartStyle = "";
		this.lineEndStyle = "";
		
		this.isLineBreak = false;
		this.lineNewpage = false;
		
		this.lineSlidesname = null;
		this.lineLinks = new Array();
		this.lineImage = null;
		this.lineSection = null;
		
		this.bobNumber = 0;
	}
	
	public function writeLineToFile ():String {
		var str:String = lineStartStyle + lineText + lineEndStyle;
		str = TextUtil.protectEntities (str);
		
		var txt:String = "";
		txt += '<newline';
		txt += ' x="' + lineX + '"';
		txt += ' y="' + lineY + '"';
		txt += ' width="' + lineWidth + '"';
		txt += ' height="' + lineHeight + '"';
		txt += ' lineBreak="' + isLineBreak + '"';
		txt += ' lineIndex="' + lineIndex + '"';
		txt += ' leading="' + lineLeading + '"';
		txt += '>';
		txt += str;
		txt += '</newline>';
		
		//store the links and its information to the  page
		for (var li:Number = 0; li < lineLinks.length; li++) {
			var bl:BookLink = lineLinks[li];
			if ((TextUtil.strIsEmpty(bl.linkName) == false) || 
				(TextUtil.strIsEmpty(bl.linkText) == false)) {
				txt += bl.writeLinkToFile();
			}
		}
		
		if (lineImage != null) {
			txt += lineImage.writeImageToFile();
		}
		
		return txt;
	}
}